package net.starelement.digwartnt.game;

import cn.nukkit.Server;
import cn.nukkit.level.Level;
import jdk.nashorn.internal.ir.Block;


/**
 * StarElement DigwarTNT 游戏地图类
 *
 * @author Ruok233
 * @since NukkitX API 1.0.9 | StarElement Project v1-alpaca
 * <p>
 * create: 2019/12/08
 * update: 2019/12/08
 */

public class Ground {

    public static Ground ground = new Ground(Server.getInstance().getLevelByName("world")); //这里暂时写死，日后更改

    private Level level;

    //单例模式 私有化构造方法
    private Ground(Level level) {
        this.level = level;
    }

    public static Ground getInstance() {
        return ground;
    }


    //格式化地图
    public void format() {
        int xb = 50;
        int yb = 7;
        int zb = 20;
        while (true) {
            for (int i = 0; i < 32; i++) {
                level.setBlockAt(xb - i, yb, zb, 46);
            }
            zb--;
            if (zb < 7) {
                break;
            }
        }

        int xr = 50;
        int yr = 7;
        int zr = 2;
        while (true) {
            for (int i = 0; i < 32; i++) {
                level.setBlockAt(xr - i, yr, zr, 46);
            }
            zr--;
            if (zr < -11) {
                break;
            }
        }
    }

    //清空地图
    public void clear() {
        int xb = 50;
        int yb = 7;
        int zb = 20;
        while (true) {
            for (int i = 0; i < 32; i++) {
                level.setBlockAt(xb - i, yb, zb, 236, 11);
            }
            zb--;
            if (zb < 7) {
                break;
            }
        }

        int xr = 50;
        int yr = 7;
        int zr = 2;
        while (true) {
            for (int i = 0; i < 32; i++) {
                level.setBlockAt(xr - i, yr, zr, 236, 14);
            }
            zr--;
            if (zr < -11) {
                break;
            }
        }
    }
}
